Page({
  data: {
    passport: {}
  },
  onShareAppMessage () {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.passport.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png'
    }
  },
  onLoad ({ id, encryptedData }) {
    this.getPassPort(id)
    this.getSharePassPort(encryptedData)
  },
  async getPassPort (id) {
    if (!id) return
    const { code, data } = await wx.http.get('/visitor/' + id)
    if (code !== 10000) return
    this.setData({
      passport: data
    })
  },
  async getSharePassPort (encryptedData) {
    if (!encryptedData) return
    const { code, data: passport } = await wx.http.get('/visitor/share/' + encryptedData)
    if (code !== 10000) return
    this.setData({ passport })
  },
  async saveQRCode () {
    const { path } = await wx.getImageInfo({
      src: this.data.passport.url
    })
    wx.saveImageToPhotosAlbum({
      filePath: path
    })
  }
})
